package com.lc.admin.web;

import com.lc.admin.base.ResponseResult;
import com.lc.admin.dto.CheckInConfigDto;
import com.lc.admin.dto.CheckInDto;
import com.lc.admin.dto.CheckInReviewDto;
import com.lc.admin.dto.SignDto;
import com.lc.admin.service.CheckInService;
import com.lc.admin.vo.CheckInVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class CheckInWeb {

    @Autowired
    CheckInService checkInService;

    @PostMapping("/checkIn/create")
    public ResponseResult checkIn(@RequestBody CheckInDto checkInDto) {
        try {
            checkInService.checkIn(checkInDto);
            return ResponseResult.success();
        } catch (Exception e) {
            return ResponseResult.error(e.getMessage());
        }
    }

    /**
     * 护理主管审批，需要查看到第一步提交的数据信息
     * @params assigneeId：查询我自己需要审批的记录
     * @params code：具体审批哪一个，是为了查询到唯一的记录
     * @params flowStatus: 流程执行到哪一步，0：养老顾问申请 1：护理主管审批 3、院长审批
     * @params taskId: 点击任务查看详情，传递任务id
     * @return
     */
    @GetMapping("/checkIn")
    public ResponseResult checkInDetails(String assigneeId,String code,Integer flowStatus,String taskId) {
        CheckInVo checkInVo = checkInService.checkInDetails(assigneeId,code,flowStatus,taskId);
        return ResponseResult.success(checkInVo);
    }

    @PostMapping("/checkIn")
    public ResponseResult config(@RequestBody CheckInConfigDto dto) {
        checkInService.config(dto);
        return ResponseResult.success();
    }

    /**
     * 护理主管审批
     * @param checkInReviewDto
     * @return
     */
    @PostMapping("/checkIn/review")
    public ResponseResult checkInReview(@RequestBody CheckInReviewDto checkInReviewDto) {
        checkInService.review(checkInReviewDto);
        return ResponseResult.success();
    }

    /**
     * 院长审批-通过
     * @param checkInId
     * @param taskId
     * @param message
     * @return
     */
    @PutMapping("/checkIn/submit")
    public ResponseResult agree(Long checkInId,String taskId,String message) {
        checkInService.agree(checkInId,taskId,message);
        return ResponseResult.success();
    }

    /**
     * 院长审批-拒绝
     * @param checkInId
     * @param taskId
     * @param message
     * @return
     */
    @PutMapping("/checkIn/reject")
    public ResponseResult reject(Long checkInId,String taskId,String message) {
        checkInService.reject(checkInId,taskId,message);
        return ResponseResult.success();
    }


    /**
     * 院长审批-驳回
     * @param checkInId
     * @param taskId
     * @param message
     * @return
     */
    @PutMapping("/checkIn/rebut")
    public ResponseResult rebut(Long checkInId,String taskId,String message) {
        checkInService.rebut(checkInId,taskId,message);
        return ResponseResult.success();
    }

    @PostMapping("/checkIn/sign")
    public ResponseResult sign(@RequestBody SignDto signDto) {
        checkInService.sign(signDto);
        return ResponseResult.success();
    }

}
